﻿@model AccountViewModel
@{
    var parent = (WebViewPage)TempData["Parent"];
    var controllerName = Model.IsOrganization ? "Organizations" : "Users";
}

@ViewHelpers.Section(parent,
         "change-email",
        @<text>@(Model.HasUnconfirmedEmailAddress ? "Pending Email Address" : "Email Address")</text>,
        @<text>@Model.CurrentEmailAddress</text>,
        @<text>
            @if (Model.HasConfirmedEmailAddress && Model.HasUnconfirmedEmailAddress)
            {
                using (Html.BeginForm("CancelChangeEmail", controllerName))
                {
                    @Html.AntiForgeryToken()

                    <div class="row">
                        <div class="col-sm-6">
                            <input type="submit" class="btn btn-brand form-control" value="Reset to Confirmed Email Address" />
                        </div>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-brand-secondary form-control" id="cancel-change-email">
                                Cancel
                            </button>
                        </div>
                    </div>
                }
            }
            else
            {
                using (Html.BeginForm("ChangeEmail", controllerName))
                {
                    @Html.AntiForgeryToken()

                    if (Model.HasPassword)
                    {
                        <div class="form-group @Html.HasErrorFor(m => m.ChangeEmail.Password)">
                            @Html.ShowLabelFor(m => m.ChangeEmail.Password)
                            @Html.ShowPasswordFor(m => m.ChangeEmail.Password, customClass: "input-brand")
                            @Html.ShowValidationMessagesFor(m => m.ChangeEmail.Password)
                        </div>
                    }
                    <div class="form-group @Html.HasErrorFor(m => m.ChangeEmail.NewEmail)">
                        @Html.ShowLabelFor(m => m.ChangeEmail.NewEmail, isrequired: true)
                        @Html.ShowTextBoxFor(m => m.ChangeEmail.NewEmail, customClass: "input-brand")
                        @Html.ShowValidationMessagesFor(m => m.ChangeEmail.NewEmail)
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <input type="submit" class="btn btn-brand form-control" value="Save" />
                        </div>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-brand-secondary form-control" id="cancel-change-email">
                                Cancel
                            </button>
                        </div>
                    </div>
                }
            }
         </text>,
         ViewData.ModelState.Keys.Any(x => x.StartsWith("ChangeEmail")),
         disabled: !Model.CanManage)